﻿@{
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "Test Report Page";

    bool hasError = false;
    string errorMessage = string.Empty;
    bool hasSuccess = false;
    string successMessage = string.Empty;
    
    if (IsPost)
    {
        if (Request.Form["actionButton"] == "download")
        {
            byte[] fileBytes = KeppelLand.Controllers.ReportController.GetClaimReport(Request.Form["download_format"]);
            Response.Clear();
            Response.ContentType = KeppelLand.Helpers.TranslationHelper.GetContentType(Request.Form["download_format"]);
            Response.AddHeader("content-disposition", "attachment; filename=" + KeppelLand.Helpers.TranslationHelper.GetFileName(Request.Form["download_format"], "Claims"));
            Response.BinaryWrite(fileBytes);
            Response.Flush();
            Response.End();
        } // if (Request.Form["actionButton"] == "submit")
            
    } // if (IsPost)
}

<div class="container-fluid main-content" role="main">
    n
    <h2>
        Test Report
    </h2>
    
    <div class="panel panel-default">
        <div class="panel-heading">Instructions (How should this page work?)</div>
        <div class="panel-body">
            <p>
                Test Report Download
            </p>

            <ul>
                <li>HR can click on download button to download report.</li>
            </ul>
        </div>
    </div>

    @if (hasError)
    {
    <div class="alert alert-danger alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <strong>Warning!</strong> @errorMessage
    </div>
    }
    @if (hasSuccess)
    {
    <div class="alert alert-success alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <strong>Success!</strong> @Html.Raw(successMessage)
    </div>
    }

    <form method="post" id="page_form">
        <input type="hidden" name="download_format" id="download_format" />
        <input type="hidden" name="actionButton" id="actionButton" />

        <button type="submit" name="actionButton" value="update" class="btn btn-primary">
            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>
            Download
        </button>

        <!-- Split button -->
        <div class="btn-group">
            <button type="button" class="btn btn-primary btn-download" onclick="download('PDF');"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Download</button>
            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                <span class="caret"></span>
                <span class="sr-only">Toggle Dropdown</span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li onclick="download('Excel');"><a href="javascript:void(0);" class="btn-download">Download as Excel</a></li>
                <li onclick="download('WORD');"><a href="javascript:void(0);" class="btn-download">Download as Word</a></li>
                <li onclick="download('IMAGE');"><a href="javascript:void(0);" class="btn-download">Download as TIFF</a></li>
            </ul>
        </div>

        @Html.Raw(successMessage)
        
    </form>

</div>

@section Scripts
{
    <script type="text/javascript" src="~/Scripts/kendo/2014.3.1119/kendo.ui.core.min.js"></script>
    <script type="text/javascript" src="~/Scripts/moment.js"></script>
    <script type="text/javascript" src="~/Scripts/moment-with-locales.js"></script>
    <script type="text/javascript">
    function download(format)
    {
        $("#page_form #actionButton").val("download");
        $("#page_form #download_format").val(format);
        $("#page_form").submit();
    }
    (function ($) {
        "use strict";
        $(document).ready(function () {
        });
    }(jQuery));
    </script>
}